package com.lepu.app.main.activity;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.app.utils.Utils;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.utils.main.ImageUtilBase;
import com.core.lib.utils.photo.UniversalImageLoadTool;
import com.eyzhs.app.R;

import java.io.File;

/*
 * 启动广告页
 */
public class AppStartActivityAdIndex extends BaseFragmentActivity {

    int mType = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        mNeedSwipeBack = false;
        mNeedStatusBar = false;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_start_activity_ad_index);

        init();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onBackPressed() {
        close();
    }

    private void init() {

        String filePath = "";
        Bundle data = getIntent().getExtras();
        if(data != null && data.size() > 0){
            mType = data.getInt("type");
            filePath = data.getString("filePath");
        }else{
            return;
        }

        File file = new File(filePath);

        if (file.exists()) {
            LinearLayout contentLayout = (LinearLayout) findViewById(R.id.contentLayout);

            WindowManager wm = (WindowManager) this
                    .getSystemService(Context.WINDOW_SERVICE);

            int width = wm.getDefaultDisplay().getWidth();
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT);
            params.width = width;
            params.height = width * 3 / 4;
            ;// width * 9 / 16;
            contentLayout.setLayoutParams(params);

            ImageView imageView = (ImageView) findViewById(R.id.imageView);

            UniversalImageLoadTool.disPlay(ImageUtilBase.getFileImageUrl(filePath), imageView, 0);

            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    close();

                    Utils.clickAd(AppStartActivityAdIndex.this, mType);
                }
            });
        }
    }

    public void viewClick(View v) {
        int rid = v.getId();
        switch (rid) {
            case R.id.finishImageView:

                close();
                break;
            default:
                break;
        }
    }

    private void close() {
        finishAnim(0, 0);
    }
}
